<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			input {
				width: 300px;
				height: 100px;
			}
		</style>
	</head>
	<body>
		<input type="button" name="" id="btn" value="按下变色" />
		<script type="text/javascript">
			var btn = document.querySelector("input");
			console.log(btn)
			btn.onkeyup = function(e) {
				e = e || window.event;
				var keyCode = e.keyCode || e.which;
				console.log(keyCode)
				if (e.key == "a") {
					btn.style.backgroundColor = "red";
				} else if (keyCode == 66) {
					btn.style.backgroundColor = "blue";
				} else if (keyCode == 67) {
					btn.style.backgroundColor = "pink";
				} else {
					btn.style.backgroundColor = "white";
				}
			}
		</script>
	</body>
</html>
